package org.droid.campus.admin.action;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.droid.campus.admin.model.UserModel;
import org.droid.campus.common.Action;
import org.droid.campus.common.Enums;
import org.droid.campus.common.WebActionHandler;

public class UserAction extends Action implements WebActionHandler{

	public UserAction(ServletContext servletContext, String actionName) {
		super(servletContext, actionName);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean prepare(HttpServletRequest request) {
		// TODO Auto-generated method stub
		
		return true;
	}

	@Override
	public HttpServletRequest Do(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		String name = request.getParameter("name");
		String pwd = request.getParameter("pwd");
		UserModel user = new UserModel();
		boolean flag;
		try {
			flag = user.checkUser(name, pwd);
			request.setAttribute(Enums.ActionType.TYPE.getDesc(),
					Enums.TypeContext.REDITECT.getDesc());
			if(flag){
				
				request.setAttribute(Enums.ActionType.DETAIL.getDesc(),
						"back.html");
			}else{
				request.setAttribute(Enums.ActionType.DETAIL.getDesc(),
				"login.html");
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			request.setAttribute(Enums.ActionType.TYPE.getDesc(),
					Enums.TypeContext.REDITECT.getDesc());
			request.setAttribute(Enums.ActionType.DETAIL.getDesc(),
					"login.html");
		}
		
		
		
		
		return request;
	}

}
